跳到主要内容Skip to main content

KV 缓存KV Cache

KV Cache

  • 硬件与部署Hardware & deployment
  • 第四段 · 看懂Stage 4 · Under the Hood
  • 引用核验 2026-11-09refs checked 2026-11-09
解决什么问题What problem it solves

让模型逐字生成时不用每一步都重算整段话,生成速度才可用。Stops the model recomputing the whole passage on every token it generates — this is what makes generation speed usable.

这是什么What it is

把已经算过的注意力中间结果缓存起来,只为新 token 计算增量。

代价是它持续占用显存——这直接决定了你的显存能撑多长的上下文。

Caching the attention intermediates already computed, so only new tokens need incremental work.

The cost is that it occupies VRAM continuously — which directly caps how long a context you can afford.

Prefill computes and caches K/V per layer; each decode step computes only the new token’s K/V instead of the whole prefix.
预填充阶段算好每层的 K/V 并缓存;解码每生成一个 token 只算新 token 的 K/V,不再重算整段。Prefill computes and caches K/V per layer; each decode step computes only the new token’s K/V instead of the whole prefix.
为什么需要知道Why it matters

这是本地部署时最常见的 OOM(显存不够)原因。上下文开大就先撞它。It is the most common cause of OOM when deploying locally. Raise the context size and you hit this first.

出处Sources
  • vLLM 前缀缓存设计Automatic Prefix Caching – vLLM design docs ↗
  • vLLM KV 缓存管理Hybrid KV Cache Manager – vLLM design docs ↗
  • 从业者深版:跑起来深水专题(AI 模型站)Practitioner deep-dive: serving deep dive guide (AI Models site) ↗
用这个术语做任务Use this term in a task

别停在定义:去任务手册看按什么顺序做、验收什么;或者按你手头的任务,筛 3 个工具候选。Don’t stop at the definition: use the task handbook for the order and checks, or filter three tool candidates for the job at hand.

任务手册 →Task handbooks → · 按任务筛 3 个候选 →Filter three candidates →